/**
 * Created with IntelliJ IDEA
 * Description:
 * User:恋恋
 * Date:2022-03-25
 * Time:23:38
 */
public class Test {
    public static void find1(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            int count = 0;
            for (int j = 0; j < arr.length; j++) {
                if (arr[i] == arr[j]) {
                    count++;
                }
            }
            if (count == 1) {
                System.out.println(arr[i]);
            }
        }
    }
    //方法二:异或的形式——相同为0，相反为1
    public static int find2(int[] arr){
        int ret=0;
        for(int i=0;i<arr.length;i++){
            ret=ret^arr[i];//N^0=N;N^N=0
        }
        return ret;
    }
        public static void main(String[] args){
            int[] arr1 = {0 ,2, 2};
            int[] arr2 = {4, 1, 2, 1, 2};
            System.out.println(find2(arr1));
            System.out.println( find2(arr2));
        }

}
